import article from '../../models/Articles';

const WxParse = require('../../wxParse/wxParse.js');
Page({
  data: {
    article: {},
    gotoNow:''
  },
  onLoad(options) {
    // 获取文章id，通过路由传递
    let id = options.id;
    // 获取数据
    article.detail(id).then( ret => {
      this.setData({
        article: ret.data.data
      });

      WxParse.wxParse('body','html', ret.data.data.body, this,3);

      // 动态修改页面窗口标题
      wx.setNavigationBarTitle({
        title: '黑马' + ret.data.data.title.substr(0,5)
      });
    });

    article.articlesCount(id);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage(ret) {
    return {
      title: this.data.article.desn,
      path: '/pages/newsdetail/newsdetail?id=' + this.data.article.id,
      imageUrl: this.data.article.pic_url
    }
  },
  onPageScroll(evt){
    if(evt.scrollTop > 100){
      this.setData({ gotoNow: 'gotoNow' });
    }else{
      this.setData({ gotoNow: '' });
    }
  }
})